﻿package net.jmp0.toast.entities.effects
{
	import flash.geom.ColorTransform;
	import punk.Actor;
	import punk.core.Entity;
	import punk.core.Spritemap;
	import punk.Textplus;
	import net.jmp0.toast.entities.bases.GameElement;
	import net.jmp0.toast.entities.player.Player;
		
	/**
	 * ...
	 * @author Thodd
	 */
	public class HUD extends Actor
	{
		//Font specs
		private var fontSize:int = 21;
		private var fontType:String = "garbage";
		
		//Texts
		private var fpsText:GameText;
		private var objectsText:GameText;
		private var playerCoordText:GameText;
		private var keyAmount:GameText;
		private var orangeAmount:GameText;

		//Graphics
		//Orange and Key Sprites
		[Embed(source = '../../res/magicorange.png')] private var imgOrange:Class;
		private var sprOrange:Spritemap = FP.getSprite(imgOrange, 22, 24, false, false, 0, 0, true);
		[Embed(source = '../../res/key.png')] private var imgKey:Class;
		private var sprKey:Spritemap = FP.getSprite(imgKey, 20, 20, false, false, 0, 0, true);
		//Marker sprites
		[Embed(source = '../../res/marker/marker_small_green.png')] private var imgGreenMarker:Class;
		private var sprGreenMarker:Spritemap = FP.getSprite(imgGreenMarker, 82, 45, false, false, 4, 3, false);
		[Embed(source = '../../res/marker/marker_small_orange.png')] private var imgOrangeMarker:Class;
		private var sprOrangeMarker:Spritemap = FP.getSprite(imgOrangeMarker, 82, 45, false, false, 0, 0, false);
		
		
		public function HUD() {
			this.delay = 7;
			
			this.depth = -100;
			this.x = 2;
			this.y = 60;
			
			//Debug texts
			/*fpsText = new GameText("fps: " + FP.engine.FPS, x, y, fontType, fontSize, depth, true);
			objectsText = new GameText("# of objects: " + FP.world.getClass(Entity).length, x, y + fontSize, "garbage", fontSize, depth, true);
			playerCoordText = new GameText("player (x,y): (" + FP.world.getClassFirst(Player).x + "," + FP.world.getClassFirst(Player).y + ")",
												x, y + 2 * fontSize, fontType, fontSize, depth, true);
			*/

			//the real HUD texts
			keyAmount = new GameText("X " + (FP.world.getClassFirst(Player) as Player).getKeys(), 60, 5, "kraboudja", 34, depth-2, true);
			orangeAmount = new GameText("X " + (FP.world.getClassFirst(Player) as Player).getOranges(), 190, 5, "kraboudja", 34, depth - 2, true);
			
			//Changing the alpha of the marker sprites
			var colorT:ColorTransform = new ColorTransform();
			colorT.alphaMultiplier = 0.5;
			sprGreenMarker.colorTransform(sprGreenMarker.rect, colorT);
			sprOrangeMarker.colorTransform(sprOrangeMarker.rect, colorT);
		}
		
		
		override public function update():void {
			//Debug
			/*fpsText.text = "fps: " + FP.engine.FPS;
			objectsText.text = "# of objects: " + FP.world.getClass(Entity).length;
			playerCoordText.text = "player (x,y): (" + FP.world.getClassFirst(Player).x + "," + FP.world.getClassFirst(Player).y + ")";
			*/
			//The real HUD
			keyAmount.text = "X " + (FP.world.getClassFirst(Player) as Player).getKeys();
			orangeAmount.text = "X " + (FP.world.getClassFirst(Player) as Player).getOranges();
			
		}
		
		
		override public function render():void {
			//Drawing the HUD etc.
			updateImage(sprOrange.number);
			drawSprite(sprGreenMarker, 0, 42, 7, false, false);
			drawSprite(sprOrangeMarker, 0, 172, 7, false, false);
			drawSprite(sprKey, image, 30, 17, false, false);
			drawSprite(sprOrange, image, 160, 14, false, false);
		}
	}

}